﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Library;

namespace Sport_Shop
{
    public partial class SanPham : System.Web.UI.Page
    {
       
        static PagedDataSource p = new PagedDataSource();
        public static int intSTT;
        public static int trang_thu = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                load_SPtheoLoai();
                
            }
        }

        private void load_SPtheoLoai()
        {
            if (Request.QueryString["MaLoai"] == null)
            {
                Response.Redirect("~/Index.aspx");
            }
            else
            {
                DataAccess da = new DataAccess();
                string ML = Request.QueryString["MaLoai"].ToString();
                string sql = "SELECT * FROM SanPham WHERE MaLoai = '" + ML + "'";
                p.DataSource = da.GetDataList(sql).Tables[0].DefaultView;
                p.PageSize = 4;
                p.CurrentPageIndex = trang_thu;
                p.AllowPaging = true;

                btDau.Enabled = true; btTruoc.Enabled = true; btSau.Enabled = true; btCuoi.Enabled = true;

                if (p.IsFirstPage == true)
                {
                    btDau.Enabled = false;
                    btTruoc.Enabled = false;
                    btSau.Enabled = true;
                    btCuoi.Enabled = true;
                }
                if (p.IsLastPage == true)
                {
                    btDau.Enabled = true;
                    btTruoc.Enabled = true;
                    btSau.Enabled = false;
                    btCuoi.Enabled = false;
                }
                tbTrang.Text = (trang_thu + 1) + "/" + p.PageCount;
                dlSanphamOfLoai.DataSource = p;
                dlSanphamOfLoai.DataBind();
            }
        }

        protected void btDau_Click(object sender, EventArgs e)
        {
            trang_thu = 0;
            load_SPtheoLoai();
        }

        protected void btTruoc_Click(object sender, EventArgs e)
        {
            trang_thu--;
            load_SPtheoLoai();
        }

        protected void btSau_Click(object sender, EventArgs e)
        {
            trang_thu++;
            load_SPtheoLoai();
        }

        protected void btCuoi_Click(object sender, EventArgs e)
        {
            trang_thu = p.PageCount - 1;
            load_SPtheoLoai();
        }

        
    }
}